/*analyses for Oneal and Tir's "Does the Diversionary Use of Force Threaten the
Democratic Peace," International Studies Quarterly, regarding major democracies:
4-7-2006*/

set mem 200m

use c:\growth\isqfinal\otnondir

desc
summ

/*drop exactly zero growth for democs b/c result of interpol of rgdppc*/
replace growth2a=. if growth2a==0 & democ_a_cg==1
replace growth2b=. if growth2b==0 & democ_b_cg==1

gen jntdem=1 if democ_a_cg==1 & democ_b_cg==1
replace jntdem=0 if jntdem==. & democ_a_cg~=. & democ_b_cg~=.

gen dem_aut=1 if autoc_a_cg==1 & democ_b_cg==1
replace dem_aut=1 if autoc_b_cg==1 & democ_a_cg==1
replace dem_aut=0 if dem_aut==. & autoc_a_cg~=.  /*autoc, democ, mixed always coded
                                                      if one known*/
gen dem_incoh=1 if democ_a_cg==1 & mixed_b_cg==1 
replace dem_incoh=1 if democ_b_cg==1 & mixed_a_cg==1 
replace dem_incoh=0 if dem_incoh==. & democ_a_cg~=.

gen aut_aut=1 if autoc_a_cg==1 & autoc_b_cg==1
replace aut_aut=1 if autoc_b_cg==1 & autoc_a_cg==1
replace aut_aut=0 if aut_aut==. & autoc_a_cg~=.  /*autoc, democ, mixed always coded
                                                      if one known*/
gen incoh_incoh=1 if mixed_a_cg==1 & mixed_b_cg==1 
replace incoh_incoh=1 if mixed_b_cg==1 & mixed_a_cg==1 
replace incoh_incoh=0 if incoh_incoh==. & mixed_a_cg~=.

/*test for growth effect in joint democratic dyads*/
#del ;
gen smlgrow=growth2a if growth2a<growth2b & growth2b~=.;
quietly by statea stateb: replace smlgrow=. if ~((leadid_a==leadid_a[_n-1] &
      leadid_a==leadid_a[_n-2])) & smlgrow==growth2a;
replace smlgrow=growth2b if growth2b<growth2a & growth2a~=.;
quietly by statea stateb: replace smlgrow=. if ~((leadid_b==leadid_b[_n-1] &
      leadid_b==leadid_b[_n-2])) & smlgrow==growth2b;
gen jntdXgr=jntdem*smlgrow;
replace jntdXgr=0 if jntdem==0;

/*test for growth effect on democs in mixed dyads*/
gen mixXgr=growth2a if dem_aut==1 & democ_a_cg==1 ;
quietly by statea stateb: replace mixXgr=. if ~((leadid_a==leadid_a[_n-1] &
      leadid_a==leadid_a[_n-2])) & mixXgr==growth2a;
replace mixXgr=growth2b if dem_aut==1 & democ_b_cg==1 ;
quietly by statea stateb: replace mixXgr=. if ~((leadid_b==leadid_b[_n-1] &
      leadid_b==leadid_b[_n-2])) & mixXgr==growth2b;
replace mixXgr=0 if mixXgr==. & dem_aut==0;

/*test for growth effect on democs in dyads with incoherent states*/
gen incohXgr=growth2a if dem_incoh==1 & democ_a_cg==1 ;
quietly by statea stateb: replace incohXgr=. if ~((leadid_a==leadid_a[_n-1] &
      leadid_a==leadid_a[_n-2])) & incohXgr==growth2a;
replace incohXgr=growth2b if dem_incoh==1 & democ_b_cg==1 ;
quietly by statea stateb: replace incohXgr=. if ~((leadid_b==leadid_b[_n-1] &
      leadid_b==leadid_b[_n-2])) & incohXgr==growth2b;
replace incohXgr=0 if incohXgr==. & dem_incoh==0;
#del cr
drop leadid* growth2a growth2b

gen dependa=trade/cgdpa
gen dependb=trade/cgdpb
drop trade cgdp* 

gen smldep=dependa if dependa<=dependb & dependb~=.  
replace smldep=dependb if dependb<dependa & dependa~=.  
gen lrgdep=dependb if dependa<=dependb & dependb~=.  
replace lrgdep=dependa if dependb<dependa & dependa~=.  

replace smldep=. if dependa>1 | dependb>1
drop depend*

/*identify fatal disputes, in year t+1*/
gen fatal1=1 if mzfatald1>0 & mzfatald1~=.
replace fatal1=0 if mzfatald1==0

gen lndstab=ln(distance)

/*identify dyads w/ land border*/
gen dircont=1 if contig<6
replace dircont=0 if contig==6

gen majpower=1 if majpow_a==1 | majpow_b==1
replace majpower=0 if majpower==.

/*create control for number of states in system*/
gen systsize=ln(numstate) if ~(dircont==1 | majpower==1)
replace systsize=0 if systsize==.

gen dyadid=(1000*statea)+stateb  

btscs fatal1 year dyadid, gen(py) nspline(3)

#del ;
/*TABLE 3, COLUMN 1*/
logit fatal1 jntdem dem_aut dem_incoh smldep lncaprat allies
      dircont lndstab majpower systsize py _spline*, nolog 
      cluster(dyadid);  

/*TABLE 3, COLUMN 2*/
logit fatal1 jntdem dem_aut dem_incoh jntdXgr mixXgr incohXgr smldep lncaprat allies
      dircont lndstab majpower systsize py _spline*,nolog cluster(dyadid);  
testparm jntdX mixX incohX;

exit;

